/*
 * @Description: 路由
 * @Author: bxsdhx
 * @Date: 2024-02-20 14:08:15
 * @LastEditTime: 2024-02-23 14:12:51
 * Copyright (C) 2024 bxsdhx. All rights reserved.
 */
import type { RouteRecordRaw } from "vue-router";
import { createRouter, createWebHashHistory } from "vue-router";
import nprogress from "nprogress";

const error = {
  path: "/:pathMatch(.*)",
  name: "error",
  component: () => import("@/pages/error.vue"),
  meta: {
    title: "404",
  },
};

export const routes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "home",
    component: () => import("@/pages/home.vue"),
    meta: {
      title: "首页",
    },
    redirect: "/test",
    children: [
      {
        path: "/test",
        name: "test",
        component: () => import("@/pages/test/index.vue"),
        meta: {
          title: "首页-测试",
        },
      },
      error,
    ],
  },
  error,
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes,
});

router.beforeEach((to, _, next) => {
  nprogress.start();
  document.title = String(to.meta.title);
  next();
});

router.afterEach(function () {
  nprogress.done();
});

export default router;
